<script setup>
import { getOrderProgress } from '@/api/visual/index'
import { formatHeaderData } from '@/utils/globalMethod'
import { formatMoney, defaultShortcuts, formatStatisticsData, timeStringToDecimal } from '@/utils/globalMethod'
import moment from 'moment'

const key = ref(1)

const sellConfig = reactive({
  header: [
    formatHeaderData('订单单号', '#3556bd'),
    formatHeaderData('产品编号', '#3556bd'),
    formatHeaderData('产品名称', '#3556bd'),
    formatHeaderData('预交货日', '#3556bd'),
    formatHeaderData('工单数量', '#3556bd'),
    formatHeaderData('未发数量', '#3556bd')
  ],
  data: [],
  index: false,
  align: ['center', 'center', 'center', 'center', 'center', 'center'],
  headerBGC: 'rgba(0,0,0,0)',
  oddRowBGC: 'rgba(0,0,0,0)',
  evenRowBGC: 'rgba(0,0,0,0)'
})

const loadData = async () => {
  const { data } = await getOrderProgress()
  sellConfig.data = data.map(item => {
    let billno = ''
    if (item.Quantity === item.wjsl) {
      billno = formatHeaderData(item.BillNO, 'red')
    } else if (item.yjsl > 0) {
      billno = formatHeaderData(item.BillNO, 'blue')
    } else if (item.wjsl === 0) {
      billno = formatHeaderData(item.BillNO, 'green')
    }

    return [
      billno,
      item.ProdID,
      item.ProdName,
      (item.yjr = item.yjr > 0 ? moment(`${item.yjr}`).format('YYYY-MM-DD') : ''),
      (item.Quantity = formatMoney(null, item.Quantity)),
      (item.wjsl = formatMoney(null, item.wjsl))
    ]
  })
}

onMounted(async () => {
  await loadData()
  window.addEventListener('resize', () => {
    nextTick(() => {
      key.value++
    })
  })
})
</script>

<template>
  <div class="ps_w_h_100">
    <ps-borderbox5 :key="key">
      <dv-scroll-board :config="sellConfig"></dv-scroll-board>
    </ps-borderbox5>
  </div>
</template>

<style scoped lang="scss">
:deep(.wh) {
  width: 100%;
  height: 100%;
}
</style>
